﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Web;
using HZ.Common;
namespace HZ.Web
{
    /// <summary>
    /// 获取Request封装
    /// </summary>
    public static class RequestHelper
    {
        /// <summary>
        /// 获取查询字符串封装
        /// </summary>
        /// <param name="str">查询字符串的键</param>
        /// <returns>获取查询字符串封装(返回ConvertHelper类的一个实例)</returns>
        /// <example>
        /// 代码示例
        /// <code>
        ///     if (HZ.Web.RequestHelper.GetQueryString("ID").String == "")
        ///     {
        ///        return;//先判断是否有参数   
        ///     }            
        ///     int i = HZ.Web.RequestHelper.GetQueryString("ID").ToInt32;
        ///     if (i == null)
        ///     {
        ///        HZ.Web.MessageBox.Show("查询数字为非数字");
        ///     }
        ///     else
        ///     {
        ///        HZ.Web.MessageBox.Show(string.Format("查询数字为：{0}", i));
        ///     }
        /// </code>
        /// </example>
        public static ConvertHelper GetQueryString(string str)
        {
            string qstr = HttpContext.Current.Request.QueryString[str];
            return new ConvertHelper(qstr);
        }
        /// <summary>
        /// 获取表单查询封装
        /// </summary>
        /// <param name="str">查询字符串的键</param>
        /// <returns>获取表单查询串封装</returns>
        /// <example>
        /// 代码实例(表单查询,post)
        /// <code>
        ///     if (HZ.Web.RequestHelper.GetFormString("ID").String == "")
        ///     {
        ///        return;//先判断是否有参数   
        ///     }            
        ///     int i = HZ.Web.RequestHelper.GetFormString("ID").ToInt32;
        ///     if (i == null)
        ///     {
        ///        HZ.Web.MessageBox.Show("查询数字为非数字");
        ///     }
        ///     else
        ///     {
        ///        HZ.Web.MessageBox.Show(string.Format("查询数字为：{0}", i));
        ///     }
        /// </code>
        /// </example>
        public static ConvertHelper GetFormString(string str)
        {
            string qstr = HttpContext.Current.Request.Form[str];
            return new ConvertHelper(qstr);
        }
    }
}
